<template>
	<view class="inquiryOrderItem-item" @click="onClick()">
		<view class="outer4">
			<view class="word3" v-if="data.oStatus==3&&!data.doctorName">支付后为您安排医生接诊</view>
			<view class="word3" v-if="data.oStatus!=3&&!data.doctorName">正在为您安排医生接诊</view>

			<view class="outer4-left" v-if="data.doctorName">
				<image :src="data.picture" class="mod4"></image>
				<view class="word4">{{ data.doctorName }}</view>
				<view class="word5">{{ data.departmentName }}</view>
			</view>
			<!-- 待支付 -->
			<view class="info2 info2-red" v-if="data.oStatus==3">{{ orderStatusList[data.oStatus] }}</view>
			<!-- 待接诊 -->
			<view class="info2 info2-red" v-else-if="data.oStatus==1&&data.qStatus==0">{{ qStatusList[data.qStatus] }}</view>
			<!-- 问诊中 -->
			<view class="info2 info2-green" v-else-if="data.qStatus==1">{{ qStatusList[data.qStatus] }}</view>
			<!-- 已开处方 -->
			<view class="info2 info2-green" v-else-if="data.qStatus==2">{{ qStatusList[data.qStatus] }}</view>
			<!-- 已退诊 -->
			<view class="info2 info2-gray" v-else-if="data.qStatus==4">{{ qStatusList[data.qStatus] }}</view>
			<!-- 退款中|已退款 -->
			<view class="info2 info2-gray" v-else-if="data.oStatus==4||data.oStatus==5">{{ orderStatusList[data.oStatus] }}</view>
			<!-- 待发货|待收货 -->
			<view class="info2 info2-purple" v-else-if="data.oStatus==7||data.oStatus==8">{{ orderStatusList[data.oStatus] }}</view>
			<!-- 已完成 -->
			<view class="info2 info2-gray" v-else-if="data.oStatus==1||data.qStatus==3">{{ qStatusList[data.qStatus] }}</view>
			<!-- 其他状态 -->
			<view class="info2 info2-purple" v-else >{{ orderStatusList[data.oStatus] }}</view>
		</view>

		<view class="paragraph1">订单类型：{{ orderTypeList[data.orderType].name }}-{{ inquiryTypeList[data.inquiryType].name }}</view>
		<view class="paragraph1">病情描述：{{ data.content }}</view>
 
		<view class="outer6">
			<view class="txt2">{{ data.createdTime }}</view>
			<view class="info3 info3-purple" v-if="data.oStatus==3" >去支付</view>
			<view v-if="data.qStatus==1||data.qStatus==2" @click.stop="onEnd" class="info3 info3-purple" >结束问诊</view>
			<!--
			<view class="info3 info3-purple" v-if="data.oStatus==1&&data.qStatus==1" @click.stop="gotoRouter('/pages-im/chatRoom/chatRoom?accid=' + data.doctorId + '&role=0'+'&questionOrderId='+data.id)">去咨询</view>
			-->
			<view class="info3 info3-purple" v-if="data.oStatus==1&&data.qStatus==1" @click.stop="gotoRouter('/pages-txy-im/chatRoom/chatRoom?accid=' + data.doctorId + '&role=0'+'&questionOrderId='+data.id)">去咨询</view>
			<view class="info3 info3-green"v-if="data.qStatus==2&&data.recipeStatus==1" @click.stop="gotoRouter('/pages-mall/orderCreate/orderCreate?orderCode=' + data.drugOrderCode)">去购药</view>

			<view class="txt3" v-if="data.qStatus==2&&data.recipeStatus==0" >等待药师审核处方</view>
			<view class="txt3" v-if="data.qStatus==2&&data.recipeStatus==4" >药师审方未通过</view>
			
			
			<view class="info3 info3-purple" v-if="data.oStatus==1&&data.qStatus==3" @click.stop="gotoRouter('/pages-member/evaluate/evaluate?doctorId=' + data.doctorId + '&orderId=' + data.orderId)">去评价</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		data: {
			type: Object,
			default() {
				return {};
			}
		}
	},

	data() {
		return {
			payFlag:true
		};
	},
	onLoad(option) {},
	onShow() {},
	methods: {
		onClick() {
			this.$emit('click');
		},
		btnClick() {
			this.$emit('btnClick');
		},
		
		//修改订单状态
		updateOrderStatus(status) {
			this.$api
				.updateOrderStatus({
					params: {
						orderId: this.questionOrderForm.orderId,
						status: status
					}
				})
				.then(res => {
					if (res.code == 200) {
						
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
				});
		},
		
		onEnd(){
			uni.showModal({
				title: '确认要结束问诊吗？',
				success: res => {
					if (res.confirm) {
						this.$api
							.manualUpdateQuestionStatus({
								params: {
									id: this.data.id
								}
							})
							.then(res => {
								if (res.code == 200) {
									this.$emit('paySuccess');
								} else {
									uni.showToast({
										title: res.message,
										icon: 'none'
									});
								}
							});
					}
				}
			});
		},

		
		//发起微信支付
		submitOrder(id) {
			if (this.payFlag) {
				this.payFlag = false;
				this.$api
					.submitOrder({
						params: {
							commodityName: '购药订单',
							orderId: id
						}
					})
					.then(res => {
						if (res.code == 200) {
							this.wxRequestPayment(res.result);
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							});
						}
					});
			}
		},
		
		//微信小程序拉起支付
		wxRequestPayment(res) {
			wx.requestPayment({
				timeStamp: res.timeStamp,
				nonceStr: res.nonceStr,
				package: res.packageValue,
				signType: res.signType,
				paySign: res.paySign,
				success: success => {
					uni.showToast({
						title: '支付成功',
						icon: 'none'
					});
					this.$emit("paySuccess")
				},
				fail: error => {
					uni.showToast({
						title: '取消支付',
						icon: 'none'
					});
				},
				complete: () => {
					this.payFlag = true;
				}
			});
		}
		
	}
};
</script>

<style lang="less">
.inquiryOrderItem-item {
	width: 686rpx;
	border-radius: 16rpx;
	background-color: rgba(255, 255, 255, 1);
	box-shadow: 0px 2rpx 10rpx 0px rgba(0, 0, 0, 0.1);
	box-sizing: border-box;
	padding: 20rpx 30rpx;
	margin-bottom: 20rpx;

	.word3 {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		color: #333333;
	}

	.outer4 {
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #eeeeee;
		padding-bottom: 10rpx;
		margin-bottom: 19rpx;
		.outer4-left {
			display: flex;
			align-items: center;
			.mod4 {
				height: 60rpx;
				border-radius: 50%;
				width: 60rpx;
				display: flex;
				flex-direction: column;
			}

			.word4 {
				color: rgba(51, 51, 51, 1);
				font-size: 28rpx;
				font-family: PingFangSC-Medium;
				margin-left: 16rpx;
			}
			.word5 {
				color: rgba(153, 153, 153, 1);
				font-size: 24rpx;
				font-family: PingFangSC-Regular;
				margin-left: 28rpx;
			}
		}

		.info2 {
			
			font-size: 28rpx;
			margin-left: auto;
		}

		.info2-green {
			color: #23c79c;
		}
		.info2-purple {
			color: #6E99C7;
		}
		.info2-gray {
			color: #999999;
		}
		.info2-red {
			color: #FF4141;
		}
	}

	.paragraph1 {
		color: rgba(51, 51, 51, 1);
		font-size: 28rpx;
		font-family: PingFangSC-Regular;
		margin-bottom: 10rpx;
	}
	.outer6 {
		margin-top: 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.txt2 {
			color: rgba(153, 153, 153, 1);
			font-size: 28rpx;
			font-family: PingFangSC-Regular;
		}
		
		
		
		.txt3 {
			overflow-wrap: break-word;
			color: rgba(255, 65, 65, 1);
			font-size: 22rpx;
			
		}
		
		
		
		.info3 {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 600;
			width: 140rpx;
			height: 48rpx;
			border-radius: 25rpx;
			justify-content: center;
			align-items: center;
			display: flex;
		}

		.info3-green {
			color: #23c79c;
			border: 1rpx solid #23c79c;
			background: #f7fffd;
		}
		.info3-purple {
			color: #6E99C7;
			border: 1rpx solid #6E99C7;
			background: #F9F7FF;
		}
		.info3-gray {
			color: #999999;
			border: 1rpx solid #999999;
			background: #999999;
		}
		.info3-red {
			color: #FF4141;
			border: 1rpx solid #FF4141;
			background: #FF4141;
		}
	}
}
</style>
